package cn.cs.service.impl;

import cn.cs.client.AgentCapitalPoolTypeClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.CapitalPoolType;
import cn.cs.service.CapitalPoolTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CapitalPoolTypeServiceImpl implements CapitalPoolTypeService {

    @Resource
    private AgentCapitalPoolTypeClient capitalPoolTypeClient;

    public CapitalPoolType getCapitalPoolTypeById(String id) throws Exception {
        return capitalPoolTypeClient.getCapitalPoolTypeById(id);
    }

    public List<CapitalPoolType> getCapitalPoolTypeListByMap(Map<String, Object> param) throws Exception {
        return capitalPoolTypeClient.getCapitalPoolTypeListByMap(param);
    }

    public Integer getCapitalPoolTypeCountByMap(Map<String, Object> param) throws Exception {
        return capitalPoolTypeClient.getCapitalPoolTypeCountByMap(param);
    }

    public Integer addCapitalPoolType(CapitalPoolType capitalPoolType) throws Exception {
        capitalPoolType.setCreateDate(new Date());
        capitalPoolType.setModifyDate(new Date());
        return capitalPoolTypeClient.addCapitalPoolType(capitalPoolType);
    }

    public Integer modifyCapitalPoolType(CapitalPoolType capitalPoolType) throws Exception {
        capitalPoolType.setModifyDate(new Date());
        return capitalPoolTypeClient.modifyCapitalPoolType(capitalPoolType);
    }

    public Integer deleteCapitalPoolTypeById(String id) throws Exception {
        return capitalPoolTypeClient.deleteCapitalPoolTypeById(id);
    }

    public Page<CapitalPoolType> queryCapitalPoolTypePageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = capitalPoolTypeClient.getCapitalPoolTypeCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CapitalPoolType> capitalPoolTypeList = capitalPoolTypeClient.getCapitalPoolTypeListByMap(param);
        page.setRows(capitalPoolTypeList);
        return page;
    }

}
